#include "power_buff.h"

CPowerBuff::CPowerBuff()
    : CBuff(ENT_BUFF_POWER,
          "buff_power",
          BUFF_TYPE_BUFF)
{
}

bool CPowerBuff::applyBuff(CPlayer *pPlayer)
{
    /**
     * Applies this buff to a specific player. This buff increases the power
     * of the weapon by 1.
     * 
     * @param CPlayer *pPlayer The player to apply the buff to.
     * @return bool Whether the buff was applied
     */
    if (pPlayer->getActiveWeapon())
    {
        if (pPlayer->getActiveWeapon()->getID() == ENT_WEAPON_BOMB)
        {
            CBomb *pBomb(dynamic_cast<CBomb*>(pPlayer->getActiveWeapon()));
            pBomb->setExplodeRadius(
                pBomb->getExplodeRadius() + 1);
            return true;
        }
    }
    return false;
}

bool CPowerBuff::removeBuff(CPlayer *pPlayer)
{
    /**
     * Removes this buff from a specific player. This decreases the power
     * of the weapon by 1.
     * 
     * @param CPlayer *pPlayer The player to remove the buff from.
     * @return bool Whether the buff was removed
     */
    if (pPlayer->getActiveWeapon())
    {
        if (pPlayer->getActiveWeapon()->getID() == ENT_WEAPON_BOMB)
        {
            CBomb *pBomb(dynamic_cast<CBomb*>(pPlayer->getActiveWeapon()));
            if (pBomb->getExplodeRadius() > 1)
            {
                pBomb->setExplodeRadius(
                    pBomb->getExplodeRadius() - 1);
                return true;
            }
        }
    }
    return false;
}